package com.example.testgit.mapstruct;

import com.example.testgit.VO.CourseVO;
import com.example.testgit.entity.CourseDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author: lyh
 * @create: 2023/4/12 11:05
 * Description：
 */
@Mapper
public interface CourseConverter {
    CourseConverter INSTANCE = Mappers.getMapper(CourseConverter.class);

    @Mappings({
            @Mapping(source = "isRetake", target = "isRetake", qualifiedByName = "retakeTrans")
    })
    CourseVO toVO(CourseDO courseDO);

    @Mappings({
            @Mapping(source = "isRetake", target = "isRetake", qualifiedByName = "retakeTrans")
    })
    List<CourseVO> toVOList(List<CourseDO> courseDOList);

    @Named("retakeTrans")
    default String retakeTrans(Integer isRetake) {
        return isRetake.equals(0) ? "否" : "是";
    }
}
